//
//  YiYuanDuoBaoViewController.m
//  1243
//
//  Created by ym on 16/6/29.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "YiYuanDuoBaoViewController.h"
#import "YiYuanDuoBaoTopTableViewCell.h"
#import "YiYuanDuoBaoYiJieXiaoTableViewCell.h"
@interface YiYuanDuoBaoViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    
}
@property (nonatomic, strong) UISegmentedControl *segment;
@property (nonatomic,strong)UITableView *tableView;

@end

@implementation YiYuanDuoBaoViewController


- (UISegmentedControl *)segment {
    if (!_segment) {
        _segment = [[UISegmentedControl alloc] initWithItems:@[@"商品",@"详情",@"评论"]];
        _segment.width = 150;
        _segment.tintColor = [UIColor clearColor];//去掉颜色,现在整个segment都看不见
        NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16], NSForegroundColorAttributeName: [UIColor whiteColor]};
        [_segment setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];//设置文字属性
        NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16], NSForegroundColorAttributeName: [UIColor lightTextColor]};
        [_segment setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
        //设置segment初始被选中的下标
        _segment.selectedSegmentIndex = 0;
    }
    return _segment;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.titleView = self.segment;
    self.segment.selectedSegmentIndex = 0;
    [self.segment addTarget:self action:@selector(segmentedControlValueChanged) forControlEvents:UIControlEventValueChanged];
    [self CreattableView];
    
}



- (void)CreattableView{
    
    
    self.tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds]  style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    //    miaoshaView = [[[NSBundle mainBundle] loadNibNamed:@"MiaoShaTopView" owner:nil options:nil] lastObject];
    //    _tableView.tableHeaderView = miaoshaView;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        return 1;
    }else{
        return 5;
    }
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
#warning 头部
        static NSString *identifier= @"YiYuanDuoBaoTopTableViewCell";
        
        YiYuanDuoBaoTopTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
        
        if (cell==nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"YiYuanDuoBaoTopTableViewCell" owner:nil options:nil] lastObject];
            
            
        }
        return cell;
        
    }else{
        static NSString *identifier= @"YiYuanDuoBaoYiJieXiaoTableViewCell";
        
        YiYuanDuoBaoYiJieXiaoTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
        
        if (cell==nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:@"YiYuanDuoBaoYiJieXiaoTableViewCell" owner:nil options:nil] lastObject];
            
            
        }
        return cell;
        
        
    }
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 460;
    }else{
        return 200;
    }
    
    
}

- (void)segmentedControlValueChanged {
    
    NSInteger index = self.segment.selectedSegmentIndex;
    if (index == 1) {
        //  [self.view addSubview:self.detailVC.view];
        //        [self.shopDetailVC.view removeFromSuperview];
        //        [self.commentVC.view removeFromSuperview];
    } else if (index == 2) {
        //        [self.view addSubview:self.commentVC.view];
        //        [self.detailVC.view removeFromSuperview];
        //        [self.shopDetailVC.view removeFromSuperview];
    } else {
        //        [self.view addSubview:self.shopDetailVC.view];
        //        [self.detailVC.view removeFromSuperview];
        //        [self.commentVC.view removeFromSuperview];
    }
}


@end
